package com.wish.g04.financing.controller;

import com.wish.g04.base.entity.SfContract;
import com.wish.g04.common.core.web.controller.BaseController;
import com.wish.g04.common.core.web.domain.AjaxResult;
import com.wish.g04.common.core.web.page.TableDataInfo;
import com.wish.g04.common.security.utils.SecurityUtils;
import com.wish.g04.financing.dto.PaymentPlanDTO;
import com.wish.g04.financing.service.PaymentPlanService;
import com.wish.g04.financing.vo.PaymentDayVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * 付款计划
 * @author tianyandong
 */
@RestController
@RequestMapping("/payment_plan")
public class PaymentPlanController extends BaseController {

    @Autowired
    private PaymentPlanService paymentPlanService;

    /**
     * 收房合同的查询
     * @param sfContract
     * @return
     */
    @GetMapping("getHouseContractList")
    public TableDataInfo getHouseContractList(SfContract sfContract) {
        startPage();
        List<SfContract> sfContractList =  paymentPlanService.getHouseContractList(sfContract);
        return  getDataTable(sfContractList);
    }

    /**
     * 根据id收房合同
     * @param id
     * @return
     */
    @GetMapping("/getHouseContractById/{id}")
    public AjaxResult getHouseContractById(@PathVariable Long id) {
        //根据id收房合同
        SfContract sfContract =  paymentPlanService.getHouseContractById(id);
        //获取可选择的账期
        List<PaymentDayVO> paymentDayVOList = paymentPlanService.getPaymentDayVOList(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("sfContract",sfContract);
        map.put("paymentDayVOList",paymentDayVOList);
        return  AjaxResult.success(map);
    }


    /**
     * 添加付款计划
     * @param paymentPlanDTO
     * @return
     */
    @PostMapping("/savePaymentPlan")
    public AjaxResult savePaymentPlan(@RequestBody PaymentPlanDTO paymentPlanDTO) {
        return  AjaxResult.success(paymentPlanService.savePaymentPlan(paymentPlanDTO));
    }
}
